import { defHttp } from '/@/utils/http/axios';
import { useMessage } from '/@/hooks/web/useMessage';

const { createConfirm } = useMessage();

enum Api {
  list = '/seal/sealLead/list',
  save = '/seal/sealLead/add',
  edit = '/seal/sealLead/edit',
  baosun = '/seal/sealLead/sealReport',
  deleteOne = '/seal/sealLead/delete',
  deleteBatch = '/seal/sealLead/deleteBatch',
  importExcel = '/seal/sealLead/importExcel',
  exportXls = '/seal/sealLead/exportXls',
  batchDelete = '/seal/sealLead/sealScrap1',
  baofei = '/seal/sealLead/sealScrap',
}
/**
 * 批量报废
 * @param params
 */
export const piliang = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认报失？',
    content: '是否报废选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({ url: Api.piliang, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
// 导出API
export const getExportUrl = Api.exportXls;
export const getImportUrl = Api.importExcel;

// 列表接口
export const list = (params) => defHttp.get({ url: Api.list, params });

// 删除单个
export const deleteOne = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.deleteOne, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};

// 批量删除
export const batchDelete = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};
export const baofei = (params, handleSuccess) => {
  createConfirm({
    iconType: 'warning',
    title: '确认报废？',
    content: '是否报废选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({ url: Api.baofei, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
};

// 保存或者更新
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({ url: url, params });
};

// 报损
export const reportDamage = (params, handleSuccess) => {
  createConfirm({
    iconType: 'error',
    title: '确认报损',
    content: '是否确认报损？',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.post({ url: Api.baosun, params }).then(() => {
        handleSuccess();
      });
    },
  });
};
